


$(document).ready(function() {
	
	var contextPath = Com_Parameter.ContextPath;
		$("#addBtn").click(function(){
			var contract_type = $("#contract_type").val();
			$("#myModal").load(contextPath+'/biz/intent/'+contract_type+'/getAssrecordsList?pageSize=10&navId='+navId,function(){ 
			    $("#myModal").modal("show");
			}); 
		});
		
	//*****************************************分页查询洽谈记录**********************************************************************
		//分页函数
		var pagination = function(pageNo,pageSize,supplierNo,supplierName,negotiationType){
			var url =contextPath+"/biz/intent/intAssociated/getAssrecordsListPage";
			$.ajax({
				type: "GET",
				url:  url+"?pageSize="+pageSize+"&pageNo="+pageNo,
				data: {"supplierName":supplierName,"supplierNo":supplierNo,"negotiationType":negotiationType},
				success: function(data) {
					var negotiationObj = eval('(' + data + ')');
					var negotiationList = negotiationObj.jsonRoot;
					$("#negotiationTbody").find("tr").each(function(){
						$(this).remove();
					});
					var tbody =$("#negotiationTbody");
					for(var i= 0;i<negotiationList.length;i++){
						
						var negotiation = negotiationList[i];
						var tr = "<tr data-herf=\"${contextPath}/biz/contract/associated/${assrecord.id}/view\" data-target=\"_self\">";
							tr += "<td class=\"o-l-tab-ckb\" >";
							tr += "	<input type=\"checkbox\" data-ckb-id=\""+negotiation.id+"\">";
							tr +="</td>";
							tr +="<td>"+negotiation.negotiation_Type+"</td>";
							tr +="<td>"+negotiation.is_Modify_Contract+"</td>";
							tr +="<td >"+negotiation.number+"</td>";
							tr +="<td >"+negotiation.supplierNo+"</td>";
							tr +="<td >"+negotiation.supplierName+"</td>";
							tr +="<td >"+negotiation.area+"</td>" ;
							tr +="<td >"+negotiation.store+"</td>";
							tr +="</tr>";
							tbody.append(tr);
					}
					var total =parseFloat(negotiationObj.total);
					var totalSize = Math.ceil(total/parseFloat(pageSize));
					$("#pageNo").val(negotiationObj.pageNo);
					$("#pageSize").val(negotiationObj.pageSize);
					$("#total").val(negotiationObj.total);
					$("#pageNoSpan").text("第"+negotiationObj.pageNo+"页");
					$("#totalSizeSpan").text("共"+totalSize+"页");
					if(negotiationObj.pageNo ==1){
						$("#lastPageLi").attr("class","disabled");
						$("#nextPageLi").attr("class","");
					}else if(negotiationObj.pageNo >=totalSize){
						$("#nextPageLi").attr("class","disabled");
						$("#lastPageLi").attr("class","");
					}else{
						$("#lastPageLi").attr("class","");
						$("#nextPageLi").attr("class","");
					}
				}
			});
		}
		
		//条件查询
		$("#queryNegotiation").click(function(){
			var supplierNo = $("#supplierno").val();
			var supplierName = $("#suppliername").val();
			var negotiationType = $("#negotiationType").val();
			var pageNo = 1;
			var pageSize = parseFloat($("#pageSize").val());
			pagination(pageNo,pageSize,supplierNo,supplierName,negotiationType);
		});
		
		//***************下一页*********
		$("#nextPage").click(function(){
			var supplierNo = $("#supplierno").val();
			var supplierName = $("#suppliername").val();
			var negotiationType = $("#negotiationType").val();
			var pageNo = parseFloat($("#pageNo").val());
			var pageSize = parseFloat($("#pageSize").val());
			var total =parseFloat($("#total").val());
			var nextPageNo = pageNo + 1;
			var totalSize = Math.ceil(total/pageSize);
			var url =contextPath+"/biz/intent/intAssociated/getAssrecordsListPage";
			if(pageNo >=totalSize){
				top.$.jBox.tip('没有下一页','warning');
				return;
			}
			pagination(nextPageNo,pageSize,supplierNo,supplierName,negotiationType);
		});
		
	 //****************************上一页*****************************
		//上一页
		$("#lastPage").click(function(){
			var supplierNo = $("#supplierno").val();
			var supplierName = $("#suppliername").val();
			var negotiationType = $("#negotiationType").val();
			var pageNo = parseFloat($("#pageNo").val());
			var pageSize = parseFloat($("#pageSize").val());
			var total =parseFloat($("#total").val());
			var nextPageNo = pageNo + 1;
			var lastPageNo = pageNo -1;
			var totalSize = Math.ceil(total/pageSize);
			
			if(pageNo <=1){
				top.$.jBox.tip('没有上一页','warning');
				return;
			}
			pagination(lastPageNo,pageSize,supplierNo,supplierName,negotiationType);
		});
		
		//跳转页面输入框只能输入正整数
		$("#gotoPageNo").keyup(function(){
			var str=$(this).val();
			var newstr='';
			 for(i=0;i<str.length;i++){
				 var j=str.charCodeAt(i);
				 if(j>47&&j<55){
					 newstr+=String.fromCharCode(j); 
				 }
			  }
			 if( newstr.charCodeAt(0)==48 ){
				 $(this).val(newstr.substr(1,newstr.length)); 
			 } else{ 
				 $(this).val(newstr); 
			}
		});
		
		//跳转到指定页面
		$("#goto").click(function(){
			var supplierNo = $("#supplierno").val();
			var supplierName = $("#suppliername").val();
			var negotiationType = $("#negotiationType").val();
			var pageNo = $("#gotoPageNo").val();
			var pageSize = parseFloat($("#pageSize").val());
			var total =parseFloat($("#total").val());
			var totalSize = Math.ceil(total/pageSize);
			if(pageNo ==null && ''==pageNo){
				top.$.jBox.tip('请输入页码','warning');
				return;
			}else if(pageNo >totalSize ||pageNo<1){
				top.$.jBox.tip('你输入的页码不在范围内','warning');
				return;
			}
			pagination(pageNo,pageSize,supplierNo,supplierName,negotiationType);
		});
});

